package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目相关接口")
public class NursingProjectController extends BaseController{
    private final NursingProjectService nursingProjectService;

    public NursingProjectController(NursingProjectService nursingProjectService) {
        this.nursingProjectService = nursingProjectService;
    }

    @GetMapping
    @ApiOperation("护理项目分页查询")
    public ResponseResult<PageResponse<NursingProjectVO>> pageQuery(@RequestParam(value = "name") String name,
                                                                    @RequestParam(value ="status",required = false) Integer status,
                                                                    @RequestParam(value ="pageNum") Integer pageNum,
                                                                    @RequestParam(value ="pageSize") Integer pageSize
                                                                    ){
        PageResponse<NursingProjectVO> page  = nursingProjectService.pageQuery(name, pageNum, pageSize, status);
        return success(page);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult addNursingProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.addNursingProject(nursingProject);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVO> getNursingProject(@PathVariable("id") Long id){

            return success(nursingProjectService.getNursingProject(id));
    }

    @PutMapping
    public ResponseResult updateNursingProject(@RequestBody NursingProject nursingProject){
        nursingProjectService.updateNursingProject(nursingProject);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    public ResponseResult startOrStopStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status){
        nursingProjectService.startOrStopStatus(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    public ResponseResult deleteNursingProject(@PathVariable("id") Long id){
        nursingProjectService.deleteNursingProject(id);
        return success();
    }

    @GetMapping("/all")
    public ResponseResult<List<NursingProjectVO>> getAllNursingProject(){

        return success(nursingProjectService.getAllNursingProject());

    }
}
